package com.cxyzy.masklayer;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class TestAdapter extends RecyclerView.Adapter<TestAdapter.VH> {
    public static class VH extends RecyclerView.ViewHolder {
        public final TextView title;
        public final View maskLayer;

        public VH(View v) {
            super(v);
            title = v.findViewById(R.id.tv_title);
            maskLayer = v.findViewById(R.id.maskLayer);
        }
    }

    private List<String> mDatas;

    public TestAdapter(List<String> data) {
        this.mDatas = data;
    }

    @Override
    public void onBindViewHolder(VH holder, int position) {
        holder.title.setText(mDatas.get(position));
        maskSelectedItems(holder, position);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }

    /**
     * 对于需要打开遮罩层的条目设置遮罩，具体根据业务来设置。
     * @param holder
     * @param position
     */
    private void maskSelectedItems(VH holder, int position) {
        if (position == 1|| position == 6) {
            holder.maskLayer.setVisibility(View.VISIBLE);
        }
        else
        {
            holder.maskLayer.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    @Override
    public VH onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycleview_relative_layout, parent, false);
        return new VH(v);
    }
}